package com.mrd.gtimp.test.service;

import com.mrd.base.BaseBiz;
import com.mrd.exception.QueryException;
import com.mrd.gtimp.test.entity.Column;
import com.mrd.gtimp.test.repository.ColumnDao;
import com.mrd.spring.repository.BaseRepository;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

/**
 * <p> application name: fsla <p> copyright: Copyright@2012 明睿达科技有限公司
 */

/**
 * @author qiul
 */
@Service
public class ColumnBiz extends BaseBiz<Column> {


    @Resource
    // 该处指定注入baseDao的dao对象
    @Qualifier("columnDao")
    public void setBaseRepository(BaseRepository<Column, String> baseRepository) {
        super.baseRepository = baseRepository;
    }

    @Resource
    private ColumnDao columnDao;


    public List<Column> findColumnNameByColumnPid(int startIndex, int size, String pid)
            throws QueryException {
        List<Column> columns = new ArrayList<Column>();
        String hql = "select id,c_name from com.mrd.web.pojo.Column where pid=:pid";
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("pid", pid);
        List<Object> objects = columnDao.findEntityByHql(hql, startIndex, size, parameters);
        for (Object o : objects) {
            Object[] rs = (Object[]) o;
            Column column = new Column();
            column.setId((String) rs[0]);
            column.setC_name((String) rs[1]);
            columns.add(column);
        }
        return columns;
    }
}
